From aa2d2111e1c151eb8632ead76d9910c5d29694f4 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 3 Sep 2016 14:55:39 -0700 Subject: [PATCH] Rename some DB/LB variables to be more consistent Change-Id: I21de9c972402144159b7b2fc824533f8cefb03e7 --- includes/db/Database.php | 15 +++++----- includes/db/loadbalancer/LoadBalancer.php | 34 +++++++++++------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 5b0f2303d5..786d5f9ee9 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -128,7 +128,7 @@ abstract class DatabaseBase implements IDatabase { */ private $mTrxTimestamp = null; /** @var float Lag estimate at the time of BEGIN */ - private $mTrxSlaveLag = null; + private $mTrxReplicaLag = null; /** * Remembers the function name given for starting the most recent transaction via begin(). * Used to provide additional context for error reporting. @@ -1028,20 +1028,21 @@ abstract class DatabaseBase implements IDatabase { * @param float $runtime Total runtime, including RTT */ private function updateTrxWriteQueryTime( $sql, $runtime ) { - $indicativeOfSlaveRuntime = true; + // Whether this is indicative of replica DB runtime (except for RBR or ws_repl) + $indicativeOfReplicaRuntime = true; if ( $runtime > self::SLOW_WRITE_SEC ) { $verb = $this->getQueryVerb( $sql ); // insert(), upsert(), replace() are fast unless bulky in size or blocked on locks if ( $verb === 'INSERT' ) { - $indicativeOfSlaveRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS; + $indicativeOfReplicaRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS; } elseif ( $verb === 'REPLACE' ) { - $indicativeOfSlaveRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS / 2; + $indicativeOfReplicaRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS / 2; } } $this->mTrxWriteDuration += $runtime; $this->mTrxWriteQueryCount += 1; - if ( $indicativeOfSlaveRuntime ) { + if ( $indicativeOfReplicaRuntime ) { $this->mTrxWriteAdjDuration += $runtime; $this->mTrxWriteAdjQueryCount += 1; } @@ -2911,7 +2912,7 @@ abstract class DatabaseBase implements IDatabase { // Get an estimate of the replica DB lag before then, treating estimate staleness // as lag itself just to be safe $status = $this->getApproximateLagStatus(); - $this->mTrxSlaveLag = $status['lag'] + ( microtime( true ) - $status['since'] ); + $this->mTrxReplicaLag = $status['lag'] + ( microtime( true ) - $status['since'] ); } /** @@ -3206,7 +3207,7 @@ abstract class DatabaseBase implements IDatabase { */ public function getTransactionLagStatus() { return $this->mTrxLevel - ? [ 'lag' => $this->mTrxSlaveLag, 'since' => $this->trxTimestamp() ] + ? [ 'lag' => $this->mTrxReplicaLag, 'since' => $this->trxTimestamp() ] : null; } diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 36df46607d..7ca0b33e8d 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -61,9 +61,9 @@ class LoadBalancer { /** @var bool|DBMasterPos False if not set */ private $mWaitForPos; /** @var bool Whether the generic reader fell back to a lagged replica DB */ - private $laggedSlaveMode = false; + private $laggedReplicaMode = false; /** @var bool Whether the generic reader fell back to a lagged replica DB */ - private $slavesDownMode = false; + private $allReplicasDownMode = false; /** @var string The last DB selection or connection error */ private $mLastError = 'Unknown error'; /** @var string|bool Reason the LB is read-only or false if not */ @@ -280,7 +280,7 @@ class LoadBalancer { # Scale the configured load ratios according to the dynamic load (if the load monitor supports it) $this->getLoadMonitor()->scaleLoads( $nonErrorLoads, $group, $wiki ); - $laggedSlaveMode = false; + $laggedReplicaMode = false; # No server found yet $i = false; @@ -289,7 +289,7 @@ class LoadBalancer { # meets our criteria $currentLoads = $nonErrorLoads; while ( count( $currentLoads ) ) { - if ( $this->mAllowLagged || $laggedSlaveMode ) { + if ( $this->mAllowLagged || $laggedReplicaMode ) { $i = ArrayUtils::pickRandom( $currentLoads ); } else { $i = false; @@ -309,7 +309,7 @@ class LoadBalancer { # All replica DBs lagged. Switch to read-only mode wfDebugLog( 'replication', "All replica DBs lagged. Switch to read-only mode" ); $i = ArrayUtils::pickRandom( $currentLoads ); - $laggedSlaveMode = true; + $laggedReplicaMode = true; } } @@ -350,8 +350,8 @@ class LoadBalancer { } if ( $i !== false ) { - # replica DB connection successful - # Wait for the session master pos for a short time + # Replica DB connection successful. + # Wait for the session master pos for a short time. if ( $this->mWaitForPos && $i > 0 ) { if ( !$this->doWait( $i ) ) { $this->mServers[$i]['slave pos'] = $conn->getSlavePos(); @@ -360,8 +360,8 @@ class LoadBalancer { if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $group === false ) { $this->mReadIndex = $i; # Record if the generic reader index is in "lagged replica DB" mode - if ( $laggedSlaveMode ) { - $this->laggedSlaveMode = true; + if ( $laggedReplicaMode ) { + $this->laggedReplicaMode = true; } } $serverName = $this->getServerName( $i ); @@ -385,7 +385,7 @@ class LoadBalancer { if ( $i > 0 ) { if ( !$this->doWait( $i ) ) { $this->mServers[$i]['slave pos'] = $this->getAnyOpenConnection( $i )->getSlavePos(); - $this->laggedSlaveMode = true; + $this->laggedReplicaMode = true; } } } @@ -1431,19 +1431,19 @@ class LoadBalancer { */ public function getLaggedSlaveMode( $wiki = false ) { // No-op if there is only one DB (also avoids recursion) - if ( !$this->laggedSlaveMode && $this->getServerCount() > 1 ) { + if ( !$this->laggedReplicaMode && $this->getServerCount() > 1 ) { try { - // See if laggedSlaveMode gets set + // See if laggedReplicaMode gets set $conn = $this->getConnection( DB_SLAVE, false, $wiki ); $this->reuseConnection( $conn ); } catch ( DBConnectionError $e ) { // Avoid expensive re-connect attempts and failures - $this->slavesDownMode = true; - $this->laggedSlaveMode = true; + $this->allReplicasDownMode = true; + $this->laggedReplicaMode = true; } } - return $this->laggedSlaveMode; + return $this->laggedReplicaMode; } /** @@ -1452,7 +1452,7 @@ class LoadBalancer { * @since 1.27 */ public function laggedSlaveUsed() { - return $this->laggedSlaveMode; + return $this->laggedReplicaMode; } /** @@ -1466,7 +1466,7 @@ class LoadBalancer { if ( $this->readOnlyReason !== false ) { return $this->readOnlyReason; } elseif ( $this->getLaggedSlaveMode( $wiki ) ) { - if ( $this->slavesDownMode ) { + if ( $this->allReplicasDownMode ) { return 'The database has been automatically locked ' . 'until the replica database servers become available'; } else { -- 2.20.1